/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ga.coordination;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

/**
 *
 * @author user
 */
public class Map1 extends JPanel {

    private final int WIDTH = 800;
    private final int HEIGHT = 800;
    /**
     * state dari program
     */
    private World world = new World();
    private int xTruk = world.factory.xPosition;
    private int yTruk = world.factory.yPosition;
    
    public int state = 1;
    private Image vendor;
    private Image factory;
    private Image grass;
    private Image water;
    private Image truck;
    
    private ImageIcon fImage;
    private ImageIcon vImage;
    private ImageIcon gImage;    
    private ImageIcon wImage;
    private ImageIcon utImage;
    private ImageIcon dtImage;
    private ImageIcon ltImage;
    private ImageIcon rtImage;
    
    private int p = Toolkit.getDefaultToolkit().getScreenSize().height-160;
    private int l = Toolkit.getDefaultToolkit().getScreenSize().height-160;
    
    private int panjang = p/10;
    private int lebar = l/10;
    
    private byte[] by ;
    private int currentTrip = 0;
    private int path;
    private byte direction;
        
    /**
     * Creates new form Map
     */        
    public Map1() {
        initComponents();
        /*
         * Loading icon pics
         */
        
        fImage = new ImageIcon("src/asset/factory.png");
        factory = fImage.getImage();  
        vImage = new ImageIcon("src/asset/vendor.png");
        vendor = vImage.getImage();
        gImage = new ImageIcon("src/asset/gras.png");
        grass = gImage.getImage();
        wImage = new ImageIcon("src/asset/water.png");
        water = wImage.getImage();
        utImage = new ImageIcon("src/asset/trucka.png");
        dtImage = new ImageIcon("src/asset/truckb.png");
        ltImage = new ImageIcon("src/asset/truckki.png");
        rtImage = new ImageIcon("src/asset/truckk.png");              
    }    
    
    @Override
    public void paint(Graphics g)
    {
        super.paint(g);
        switch(state){
            case 0: break;
            case 1: {
                        for(int j = 0; j < 10; j++){
                            for(int i = 0; i < 10; i++){
                                g.drawImage(grass, i*panjang, j*lebar, panjang, lebar, this);
                            }                            
                        }
                        for(int i = 2; i < 5; i++){                            
                            g.drawImage(water, 4*panjang, i*lebar, panjang, lebar, this);
                        }
                        for(int i = 5; i < 10; i++){                            
                            g.drawImage(water, 6*panjang, i*lebar, panjang, lebar, this);
                        }
                        for(int i = 1; i < 4; i++){                            
                            g.drawImage(water, 1*panjang, i*lebar, panjang, lebar, this);
                        }
                        g.drawImage(factory, 0*panjang, 0*lebar, panjang, lebar, this);
                        g.drawImage(vendor, 1*panjang, 0*lebar, panjang, lebar, this);
                        g.drawImage(vendor, 9*panjang, 9*lebar, panjang, lebar, this);                        
                        g.drawImage(vendor, 5*panjang, 4*lebar, panjang, lebar, this);
                        g.drawImage(vendor, 4*panjang, 1*lebar, panjang, lebar, this);
                        truck = dtImage.getImage();
                        g.drawImage(truck, 0*panjang, 1* lebar, panjang, lebar, this);
                        break;
                    }
        }
        
    }
    
private void moveTruk(Graphics g, byte z){
    switch(z){
        case 0 : {
                    g.drawImage(truck, xTruk, yTruk-panjang, panjang, lebar, this);
                    yTruk = yTruk-panjang;
                    break;
                }
        case 1 : {
                    g.drawImage(truck, xTruk-lebar, yTruk, panjang, lebar, this);
                    xTruk = xTruk-lebar;
                    break;
                }
        case 2 : {
                    g.drawImage(truck, xTruk, yTruk+panjang, panjang, lebar, this);
                    yTruk = yTruk+panjang;
                    break;
                }
        case 3 : {
                    g.drawImage(truck, xTruk+lebar, yTruk-panjang, panjang, lebar, this);
                    xTruk = xTruk+lebar;
                    break;
                }
    }
}
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
